/**
 * Created by Administrator on 2019/4/21.
 */
var table;
var parentCode;
$(function () {
    parentCode = locations.ParamString("parentCode");
    table = $("#custOrderList");
    initComponent();
    initGrid();
});
function initComponent() {
    var curr_time = new Date();
    var strDate = curr_time.getFullYear() + "-";
    strDate += curr_time.getMonth() + 1 + "-";
    strDate += curr_time.getDate() + " 00:00:00";
    $("#startTime").datetimebox("setValue", strDate);
    $("#endTime").datetimebox("setValue", addDate(curr_time, 0) + " 23:59:59");
}

function initGrid(){
    var param = queryButtonLimit(parentCode);
    table.datagrid({
        iconCls : 'icon-ok',
        pageSize : 10,
        pageList : [ 10, 20, 40, 80 ],
        striped : true,
        collapsible : false,
        remoteSort : true,// 服务器端排序
        fitColumns : false,
        singleSelect : true,
        showFooter : true,
        checkOnSelect: false,
        selectOnCheck: false,
        columns : [[{
            field : 'id',
            checkbox : true,
            hidden:true
        }, {
            field : 'orderNo',
            title : '订单编号',
            width : 150,
            align : 'center'
        }, {
            field : 'orderTitle',
            title : '订单内容',
            width : 200,
            align : 'center'
        }, {
            field : 'merchantName',
            title : '商户名称',
            width : 120,
            align : 'center'
        }, {
            field : 'num',
            title : '数量',
            checkbox : true,
            width : 100,
            align : 'center'
        }, {
            field : 'status',
            title : '状态',
            width : 120,
            align : 'center',
            formatter:function (value, row, index) {
                if(value=="producing") {
                    return "生产中";
                } else if(value=="finished") {
                    return "已完成";
                } else if(value=="settled") {
                    return "已结款";
                } else {
                    return "未知";
                }
            }
        }, {
            field : 'requireTime',
            title : '要求完成时间',
            width : 200,
            align : 'center',
            formatter:function (value, row, index) {
                if(row.requireTime == null) {
                    return "";
                }
                return dateFtt("yyyy-MM-dd hh:mm:ss",new Date(row.requireTime));
            }
        }, {
            field : 'completeTime',
            title : '完成时间',
            width : 200,
            align : 'center',
            formatter:function (value, row, index) {
                if(row.completeTime == null) {
                    return "";
                }
                return dateFtt("yyyy-MM-dd hh:mm:ss",new Date(row.completeTime));
            }
        }, {
            field : 'settleTime',
            title : '结算时间',
            width : 200,
            align : 'center',
            formatter:function (value, row, index) {
                if(row.settleTime == null) {
                    return "";
                }
                return dateFtt("yyyy-MM-dd hh:mm:ss",new Date(row.settleTime));
            }
        }, {
            field : 'entryNickname',
            title : '创建人',
            width : 120,
            align : 'center'
        }, {
            field : 'entryTime',
            title : '创建时间',
            width : 200,
            align : 'center',
            formatter:function (value, row, index) {
                if(row.entryTime == null) {
                    return "";
                }
                return dateFtt("yyyy-MM-dd hh:mm:ss",new Date(row.entryTime));
            }
        }
        ]],
        pagination : true,
        rownumbers : true,
        toolbar : param,
        onBeforeLoad : function(param) {
            var parameter = new Object();
            parameter.page = param.page;
            parameter.rows = param.rows;
            if($("#orderNo").val()!="") parameter.orderNo = $("#orderNo").val();
            if($("#status").val()!="") parameter.status = $("#status").val();
            if($("#merchantPhone").val()!="") parameter.merchantPhone = $("#merchantPhone").val();
            if($("#merchantName").val()!="") parameter.merchantName = $("#merchantName").val();
            if($("#startTime").val()!="") parameter.startTime = $("#startTime").val();
            if($("#endTime").val()!="") parameter.endTime = $("#endTime").val();
            var jsonstr = postSyncAjax("/queryCustOrder/normal", parameter);
            //console.log(jsonstr);
            //console.log(jsonstr.data);
            var json = jsonstr.data;
            var dataGridData = new Object();
            dataGridData.rows = json.rows;
            dataGridData.total = json.total;
            table.datagrid('loadData', dataGridData);
        }
    });
}